PS53011C/PS71020E Lab Worksheet
0.1 📊 Lab Instructions
This week’s lab will explore multiple regression using tidyverse principles!
0.2 📽️ Slides
🧭 These are your slides for the week!
Use the arrow keys to navigate through the slides:
- ⬅️ and ➡️ to move left and right
- ⬆️ and ⬇️ for nested (vertical) slides
- Press
Escto view the slide overview- Press
Ffor fullscreen (or use browser controls)- Press
Oto toggle the overview mode- Press
Sto open the Speaker Notes window (in presenter mode)💡 Slides are best viewed in fullscreen for clarity.
1 Week 4: Multiple Regression (Part 1)
Please attempt all questions in your own words. Model answers will be available on the VLE page following the lab session.
2 Learning Outcomes
- Conduct simple and multiple linear regression analyses using R and the Tidyverse.
- Explore relationships between regression coefficients and correlation measures.
- Assess assumptions of linear regression including normality, linearity, and multicollinearity.
- Compute and interpret simple, partial, and semipartial correlations in R.
3 Materials
4 Dataset Overview
The dataset includes reaction time (RT) data for participants responding to emotional facial expressions. Of particular interest is the average RT to fearful faces for correct identifications. Predictors include:
-
traitanx: Trait anxiety (Spielberger scale) -
ACS: Attentional Control Scale score -
Age: Participant age
5 Task 1: Descriptive Statistics and Visualisation
- Load the dataset
- Create summary statistics and visualizations for RT, traitanx, ACS, and Age.
fearful_data <- read_csv("data/fearful_faces.csv")
fearful_data %>%
summarise(across(c(Fearful_face_RT, Happy_face_RT, traitanx, ACS, Age), list(mean = mean, sd = sd), na.rm = TRUE))| Fearful_face_RT_mean | Fearful_face_RT_sd | Happy_face_RT_mean | Happy_face_RT_sd | traitanx_mean | traitanx_sd | ACS_mean | ACS_sd | Age_mean | Age_sd |
|---|---|---|---|---|---|---|---|---|---|
| 0.4913926 | 0.0603538 | 0.4889262 | 0.0599826 | 41.67532 | 10.24238 | 50.19737 | 8.294608 | 23.38462 | 7.047576 |
fearful_data %>%
pivot_longer(cols = c(Fearful_face_RT, Happy_face_RT, traitanx, ACS, Age), names_to = "variable", values_to = "value") %>%
ggplot(aes(x = value)) +
geom_histogram(bins = 30, fill = "steelblue", color = "white") +
facet_wrap(~ variable, scales = "free") +
theme_minimal()6 Task 2: Correlation Analysis
- Compute a correlation matrix
- Visualize relationships using scatterplots
fearful_data %>%
select(Fearful_face_RT, Happy_face_RT, traitanx, ACS, Age) %>%
cor(use = "complete.obs") %>%
round(2) Fearful_face_RT Happy_face_RT traitanx ACS Age
Fearful_face_RT 1.00 0.96 -0.33 0.18 0.04
Happy_face_RT 0.96 1.00 -0.37 0.14 0.02
traitanx -0.33 -0.37 1.00 -0.36 -0.14
ACS 0.18 0.14 -0.36 1.00 0.36
Age 0.04 0.02 -0.14 0.36 1.00
pairs(fearful_data %>% select(Fearful_face_RT, Happy_face_RT, traitanx, ACS, Age), main = "Scatterplot Matrix")7 Task 3: Multiple Regression
- Conduct a multiple regression predicting Fearful_face_RT from traitanx, ACS, and Age.
Call:
lm(formula = Fearful_face_RT ~ traitanx + ACS + Age, data = fearful_data)
Residuals:
Min 1Q Median 3Q Max
-0.105742 -0.043660 -0.002261 0.044587 0.116670
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.5470081 0.0637205 8.584 1.9e-12 ***
traitanx -0.0018929 0.0007492 -2.527 0.0138 *
ACS 0.0005506 0.0009446 0.583 0.5619
Age -0.0002299 0.0010605 -0.217 0.8290
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.05698 on 68 degrees of freedom
(17931 observations deleted due to missingness)
Multiple R-squared: 0.1149, Adjusted R-squared: 0.07587
F-statistic: 2.943 on 3 and 68 DF, p-value: 0.0391
8 Task 4: Model Diagnostics
- Check linear regression assumptions.
9 Task 5: Partial and Semipartial Correlations
# Load required libraries
library(tidyverse)
library(ppcor)
# Calculate partial correlations
partial_data <- fearful_data %>%
dplyr::select(Fearful_face_RT, traitanx, ACS, Age) %>%
drop_na()
pcor_result <- pcor(partial_data, method = "pearson")
pcor_result$estimate
Fearful_face_RT traitanx ACS Age
Fearful_face_RT 1.00000000 -0.29295465 0.07051172 -0.02627832
traitanx -0.29295465 1.00000000 -0.29776049 -0.02300362
ACS 0.07051172 -0.29776049 1.00000000 0.33458467
Age -0.02627832 -0.02300362 0.33458467 1.00000000
$p.value
Fearful_face_RT traitanx ACS Age
Fearful_face_RT 0.00000000 0.01384887 0.561885102 0.829035513
traitanx 0.01384887 0.00000000 0.012298804 0.850075844
ACS 0.56188510 0.01229880 0.000000000 0.004640019
Age 0.82903551 0.85007584 0.004640019 0.000000000
$statistic
Fearful_face_RT traitanx ACS Age
Fearful_face_RT 0.0000000 -2.5266180 0.5829054 -0.2167714
traitanx -2.5266180 0.0000000 -2.5720632 -0.1897429
ACS 0.5829054 -2.5720632 0.0000000 2.9277975
Age -0.2167714 -0.1897429 2.9277975 0.0000000
$n
[1] 72
$gp
[1] 2
$method
[1] "pearson"
10 Task 6: Semipartial (Part) Correlation
This task explores how to isolate the unique contribution of one predictor (e.g., trait anxiety) to a dependent variable (reaction time), controlling for other variables only in the predictor.
10.1 Objective
- Calculate a semipartial correlation between
Fearful_face_RTandtraitanx, controlling forACSandAgeonly in the predictor.
# Load tidyverse if not already
library(tidyverse)
# Ensure your data is clean
semipartial_data <- fearful_data %>%
dplyr::select(Fearful_face_RT, traitanx, ACS, Age) %>%
drop_na()
# Step 1: Residualize the predictor (traitanx ~ ACS + Age)
resid_traitanx <- lm(traitanx ~ ACS + Age, data = semipartial_data)$residuals
# Step 2: Compute correlation between raw DV and residualized predictor
semipartial_corr <- cor(semipartial_data$Fearful_face_RT, resid_traitanx)
semipartial_corr[1] -0.2882545
Interpretation: This semipartial correlation represents the unique association between trait anxiety and fearful face reaction time, controlling for ACS and Age only in trait anxiety. Unlike partial correlation, it leaves the DV unadjusted.
11 Reflection
- How does anxiety influence reaction time to fearful faces?
- Does attentional control modify this relationship?
- Are the findings specific to fearful stimuli, or would they generalize to other emotional expressions?
Review your code and interpretations. Cross-reference with theoretical models on anxiety and attentional control.